//
// Created by 123 on 2025/1/6.
//
#include "iostream"
#include "string"
using namespace std;

template<class NameType,class AgeType=int>
class Person{
public:
    Person(NameType name,AgeType age){
        this->mName = name;
        this->mAge = age;
    }
    void showPerson(){
        cout << "name:" << this->mName << " age:" << this->mAge << endl;
    }
public:
    NameType mName;
    AgeType mAge;
};
//1-指定传入的类型
void printPerson1(Person<string,int> &p){
    p.showPerson();
}
void test1(){
    Person<string,int> p("zhangsan",666)    ;
    printPerson1(p);
}

//2-参数模板化
template<class T1,class T2>
void printPerson2(Person<T1,T2> &p){
    p.showPerson();
    cout << "T1 type==" << typeid(T1).name() << endl;
    cout << "T2 type==" << typeid(T2).name() << endl;
}

void test2(){
    Person<string,int> p("lisi",999);
    printPerson2(p);
}

//3-整个类模板化
template<class T>
void printPerson3(T &p){
    cout << "T type=" << typeid(T).name() << endl;
    p.showPerson();
}

void test3(){
    Person<string,int> p("stt",111);
    printPerson3(p);
}

int main103(){
    test1();
    test2();
    test3();

    return 0;
}

